<?php 
 include_once dirname(__FILE__)."/config.php";
 class aa_partenaire_attachment_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id_attachment;
		 protected $_file;
		 protected $_file_name;
		 protected $_id_owner;
		 protected $_mime;
		 public function get_name_table(){ return "aa_partenaire_attachment";}
		 public function get_name_id_attachment(){ return "id_attachment";}
		 public function get_name_file(){ return "file";}
		 public function get_name_file_name(){ return "file_name";}
		 public function get_name_id_owner(){ return "id_owner";}
		 public function get_name_mime(){ return "mime";}
		 public function set_id_attachment($parametre){  $this->_id_attachment=$parametre;}	
		 public function set_file($parametre){  $this->_file=$parametre;}	
		 public function set_file_name($parametre){  $this->_file_name=$parametre;}	
		 public function set_id_owner($parametre){  $this->_id_owner=$parametre;}	
		 public function set_mime($parametre){  $this->_mime=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id_attachment(){ return $this->_id_attachment;}
		 public function get_file(){ return $this->_file;}
		 public function get_file_name(){ return $this->_file_name;}
		 public function get_id_owner(){ return $this->_id_owner;}
		 public function get_mime(){ return $this->_mime;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 aa_partenaire_attachment(
			file,
			file_name,
			id_owner,
			mime)
 VALUES(
			'".$this->_file."',
			'".$this->_file_name."',
			'".$this->_id_owner."',
			'".$this->_mime."')";
			
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_file)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
file='".$this->_file."'";
}
if(!empty($this->_file_name)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
file_name='".$this->_file_name."'";
}
if(!empty($this->_id_owner)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_owner='".$this->_id_owner."'";
}
if(!empty($this->_mime)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
mime='".$this->_mime."'";
}
$sql="UPDATE 
aa_partenaire_attachment SET 
 ".$sql."
								WHERE 1=1  AND id_attachment ='".$this->_id_attachment."'";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
aa_partenaire_attachment 
 
									WHERE 1=1  AND id_attachment ='".$this->_id_attachment."'";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
aa_partenaire_attachment ";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id_attachment,
		file,
		file_name,
		id_owner,
		mime
 FROM 
 aa_partenaire_attachment";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function countRowInTable($constraint="")
{

$sql=" SELECT 
  COUNT(*) AS total 
 FROM 
 aa_partenaire_attachment ";
	$this->_result=$this->_cnn->query($sql);
$donnees_total=mysql_fetch_assoc($this->_result);
return $donnees_total['total'];
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id_attachment=$row->id_attachment;
		$this->_file=$row->file;
		$this->_file_name=$row->file_name;
		$this->_id_owner=$row->id_owner;
		$this->_mime=$row->mime;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>